<?php
declare (strict_types=1);

namespace app\common\model;

use ffhome\frame\model\BaseModel;
use think\facade\Db;

class TallyTodo extends BaseModel
{
    const MODEL_NAME = 'tally_todo';

    public static function findByMonthId($id)
    {
        return Db::name(self::MODEL_NAME)->whereIn('month_id', $id)
                ->limit(1)->count() != 0;
    }

    public static function findByDayId($id)
    {
        return Db::name(self::MODEL_NAME)->whereIn('day_id', $id)
                ->limit(1)->count() != 0;
    }

    public static function createEmpty($dayId)
    {
        $data = ['day_id' => $dayId];
        $data['create_by'] = $data['update_by'] = currentUserId();
        $data['create_time'] = $data['update_time'] = date('Y-m-d H:i:s');
        return Db::name(self::MODEL_NAME)->insertGetId($data);
    }

    public static function getListByDayId($dayId)
    {
        return Db::name(self::MODEL_NAME)->where(['day_id' => $dayId])->select()->toArray();
    }
}